//此代码来自洛谷 chengyueyi
#include <iostream>
using namespace std;
char a[101][101];      //地图
int b[101][101] = {0}; //答案
int n, m, i, j;
int dx[8] = {1, 0, -1, 0, -1, 1, 1, -1}; //方向
int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1}; //方向
void dfs(int x, int y)                   //调用函数将地雷周围的数加起来
{
    int nx, ny, k;
    for (k = 0; k < 8; k++)
    {
        nx = x + dx[k];
        ny = y + dy[k];
        if (nx >= 1 && nx <= n && ny >= 1 && ny <= n) //判断数组是否越界
            b[nx][ny]++;
    }
}
int main()
{
    cin >> n >> m; //输入
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            if (a[i][j] == '*')
                dfs(i, j); //如果是地雷就调用函数
        }
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            if (a[i][j] == '*') //判断是地雷就直接输出
                cout << a[i][j];
            else
                cout << b[i][j]; //不是地雷输出答案
    return 0;
}